import {
  getModelList,
  getListinfo,
  getDrgoodsShowpic,
  getModelCate,
  get_relatedcommendlist,
  get_hotDocumentList,
} from "@/assets/api/modelAreaApi";


export const state = () => ({

  modelList: [],

  modeInfo: null,
  //当前选中的一级


  recommendRes: null,

  // csList: [],
  // gzList: [],
  // htList: [],
  // ghList: [],
  // byjList: [],
  // bgList: [],

  csList: null,
  gzList: null,
  htList: null,
  ghList: null,
  byjList: null,
  bgList: null,

  cate: null,

  ModelAreaRes: null,

  relatedcommendlist: [],
  hotDocumentList: []

})

export const getters = {
  modelList: state => state.modelList,
  modeInfo: state => state.modeInfo,
  recommendRes: state => state.recommendRes,
}

export const mutations = {

  set_modelList(state, data) {
    state.modelList = data;
  },
  set_modeInfo(state, data) {
    state.modeInfo = data;
  },

  set_recommendRes(state, data) {
    state.recommendRes = data;
  },

  set_cate(state, data) {
    state.cate = data;
  },


  set_Init(state, data) {
    state.csList = data.csList
    state.gzList = data.gzList
    state.htList = data.htList
    state.ghList = data.ghList
    state.byjList = data.byjList
    state.bgList = data.bgList
  },

  set_ModelAreaRes(state, data) {
    state.ModelAreaRes = data;
  },

  set_relatedcommendlist(state, data) {
    state.relatedcommendlist = data;
  },

  set_hotDocumentList(state, data) {
    state.hotDocumentList = data;
  },
}

export const actions = {
  async getModelList({
    commit,
    state
  }, params) {
    const res = await getModelList(params)
    if (res.code == 1) {
      commit('set_modelList', res.data.list)
    }
  },

  async getListinfo({
    commit,
    state
  }, params) {
    const res = await getListinfo(params)
    if (res.code == 1) {
      commit('set_modeInfo', res)
      const res1 = await get_relatedcommendlist({
        title: res.data.title,
      });
      if (res1.code == 1)
        commit('set_relatedcommendlist', res1.data.list)

      const res2 = await get_hotDocumentList({
        title: res.data.title,
      });
      if (res2.code == 1)
        commit('set_hotDocumentList', res2.data)
    }

  },

  async Init({
    commit,
    state
  }, params) {
    const res = await getDrgoodsShowpic({});
    if (res.code == 1)
      commit('set_recommendRes', res)

    const cate = await getModelCate({});
    if (cate.code == 1)
      commit('set_cate', cate)

    const res1 = await getModelList({
      page: 1,
      pagesize: 4,
      s_tid: 2,
      tid: 1,
    });
    const res2 = await getModelList({
      page: 1,
      pagesize: 4,
      s_tid: 6,
      tid: 2,
    });
    const res3 = await getModelList({
      page: 1,
      pagesize: 4,
      s_tid: 12,
      tid: 3,
    });
    const res4 = await getModelList({
      page: 1,
      pagesize: 4,
      s_tid: 30,
      tid: 12,
    });
    const res5 = await getModelList({
      page: 1,
      pagesize: 4,
      s_tid: 9,
      tid: 11,
    });
    const res6 = await getModelList({
      page: 1,
      pagesize: 4,
      s_tid: 36,
      tid: 8,
    });
    // commit('set_Init', {
    //     csList: res1.data.list,
    //     gzList: res2.data.list,
    //     htList: res3.data.list,
    //     ghList: res4.data.list,
    //     byjList: res5.data.list,
    //     bgList: res6.data.list,
    // })
    commit('set_Init', {
      csList: res1,
      gzList: res2,
      htList: res3,
      ghList: res4,
      byjList: res5,
      bgList: res6,
    })
  },

  async ModelAreaInit({
    commit,
    state
  }, params) {

    let res = await getModelList(params);
    if (res.code == 1) {
      commit('set_ModelAreaRes', res)
    }
  },


}
